<?php
$perms =& $AppUI->acl();
$canEdit = $perms->checkModuleItem('quotations', 'edit');
if (!$canEdit) {
	$AppUI->setMsg( 'Access denied', UI_MSG_ERROR, true );
	$AppUI->redirect();
}
?>
<?php

require_once('quotation_files.class.php');
$file_id = intval(dPgetParam($_POST, 'file_id', 0));
$quote_id = intval(dPgetParam($_POST, 'quote_id', 0));
// check permissions for this record
//$canEdit = !getDenyEdit($m, $quote_id);
$canEdit = 1;
if(!$canEdit and $file_id > 0) {
	 $AppUI->setMsg('Edit Permission Deny', UI_MSG_ERROR);
	 $AppUI->redirect(PUBLIC_PAGE);
}
// instance Object File
$obj = new CQuotation_files();
// load the record data in case of that this script is used to edit the quote qith quotation_id(transmitted via GET)
if($file_id > 0 and !$obj->load($file_id, false)) {
	//$AppUI->setMsg('Quotations');
	//$AppUI->setMsg("invalidID", UI_MSG_ERROR, true);
	//$AppUI->redirect();
	//go back to the calling location
}

$msg = '';
// $canDelete = $obj->canDelete($msg, $quote_id);

// setup the title block
$ttl = $file_id > 0 ? 'Edit File' : 'Create File';
$titleBlock = new CTitleBlock($ttl, 'quotations.jpg', $m, "$m.$a");
// also have a breadcrumb here
$row = null;
if($canEdit and $file_id > 0) {
	$obj->load($file_id);
	$row = $obj;
}
$view = '';
// There are 4 cases
$cmd = 'update';
if($file_id > 0){
	$cmd = 'update';
}
else{
	$cmd = 'put';
}

?>
<form name="editFileFrm" action="./index.php?m=quotations" method="post" enctype="multipart/form-data">
<input type="hidden" name="dosql" value="do_file_crud" />
<input type="hidden" name="del" value="0" />
<input type="hidden" name="qfile_id" value="<?=$file_id?>" />
<input type="hidden" name="qfile_quote" value="<?=$quote_id?>" />
<input type="hidden" name="cmd" value="<?=$cmd?>" />
<table cellspacing="0" cellpadding="4" border="0" width="400px" class="infopanel">
<tr>
	<th colspan="100%" style="cursor: default" class="last"><?=$ttl?></th>
</tr>
<tr>
	<td>
		<input class="button" type="submit" name="saveAction" value="<?=$AppUI->_('save');?>"/>
		<input class="button" type="button" name="cancelAction" value="<?=$AppUI->_('cancel');?>" onclick="Dialog('idCRUDFileDialog').hide();"/>
	</td>
</tr>
<tr>
	<td colspan="100%">
		<table cellspacing="0" cellpadding="4" border="0" width="400px">
			<tr>
				<td> * <?=$AppUI->_('File Name')?></td>
				<td>
					<input type="text" class="text" name="qfile_name" id="code" value="<?=@$row->qfile_name?>" size="50" maxlength="50"/>
				</td>
			</tr>
			<tr>
				<td nowrap="nowrap"> * <?=$AppUI->_('File Upload')?></td>
				<td>
					<input type="file" name="file_upload" id="id_file_upload" value="<?=@$row->qfile_path?>" size="50" maxlength="50"/>
				</td>
			</tr>
			<tr>
				<td> * <?=$AppUI->_('Version')?></td>
				<td><?=createSpinBox('qfile_version', '1.0', 0, 10, '', 0.1)?></td>
			</tr>
			<tr>
				<td>
					<?=$AppUI->_('Description')?>
				</td>
				<td colspan="3">
					<textarea name="qfile_description" rows="3" cols="60"><?=@$row->qfile_description?></textarea>
				</td>
			</tr>
		</table>
	</td>
</tr>
</table>
</form>